<?php
include_once('../config.php');

$dom = new DomDocument("1.0", "utf-8");

$rss = $dom->createElement("rss");
$dom->appendChild($rss);
$rss->setAttribute(version, "2.0");

	$channel = $dom->createElement("channel");
	$rss->appendChild($channel);
	
		$title = $dom->createElement("title");
		$channel->appendChild($title);
		$title_v = $dom->createTextNode("TRUNG TÂM ĐÀO TẠO ĐIỆN ẢNH VÀ TRUYỀN THÔNG");
		$title->appendChild($title_v);
		
		$description = $dom->createElement("description");
		$channel->appendChild($description);
		$description_v = $dom->createTextNode("Thăng hoa tài năng Việt - TRUNG TÂM ĐÀO TẠO ĐIỆN ẢNH VÀ TRUYỀN THÔNG");
		$description->appendChild($description_v);
		
		$link = $dom->createElement("link");
		$channel->appendChild($link);
		$link_v = $dom->createTextNode("http://".$row_config['domain']);
		$link->appendChild($link_v);
		
		$copyright = $dom->createElement("copyright");
		$channel->appendChild($copyright);
		$copyright_v = $dom->createTextNode("www.tainangviet.vn");
		$copyright->appendChild($copyright_v);
		
		$generator = $dom->createElement("generator");
		$channel->appendChild($generator);
		$generator_v = $dom->createTextNode("www.tainangviet.vn:http://www.tainangviet.vn/RSS");
		$generator->appendChild($generator_v);
		
		$pubDate = $dom->createElement("pubDate");
		$channel->appendChild($pubDate);
		$pubDate_v = $dom->createTextNode(date('d/m/Y H:i:s'));
		$pubDate->appendChild($pubDate_v);
		
		$lastBuildDate = $dom->createElement("lastBuildDate");
		$channel->appendChild($lastBuildDate);
		$lastBuildDate_v = $dom->createTextNode(date('d/m/Y H:i:s'));
		$lastBuildDate->appendChild($lastBuildDate_v);
		
		/*info*/
		$tin = mysql_query("SELECT name,name_rewrite,url_hinh,description,date_update,menu_id FROM info WHERE `delete`=0 AND status=1 ORDER BY date_update DESC LIMIT 20");
		while($row_tin = mysql_fetch_array($tin)) { //begin vong lap $tin
			$link_detail = $tc->link_detail($row_tin['menu_id']);
			$link_view = 'http://'.$domain.'/'.$link_detail.$row_tin['name_rewrite'].'.html';
			if($row_tin['url_hinh']!='') $image = '<a href="'.$link_view.'" title="'.$row_tin['name'].'"><img src="http://'.$domain.'/'.url_articles_thumb_image.$row_tin['url_hinh'].'" alt="'.$row_tin['name'].'" /></a>'; else $image = '';
			$item = $dom->createElement("item");
			$channel->appendChild($item);
			
				$title = $dom->createElement("title");
				$item->appendChild($title);
				$title_v = $dom->createTextNode($row_tin['name']);
				$title->appendChild($title_v);
				
				$description = $dom->createElement("description");
				$item->appendChild($description);
				$description_v = $dom->createTextNode($image.$row_tin['description']);
				$description->appendChild($description_v);
				
				$link = $dom->createElement("link");
				$item->appendChild($link);
				$link_v = $dom->createTextNode($link_view);
				$link->appendChild($link_v);
				
				$pubDate = $dom->createElement("pubDate");
				$item->appendChild($pubDate);
				$pubDate_v = $dom->createTextNode(date('d/m/Y H:i:s',strtotime($row_tin['date_update'])));
				$pubDate->appendChild($pubDate_v);
		} //vong lap $tin
			
$dom->formatOutput = true;
$dom->save("../rss/tainangviet.rss");
echo 'Successful update';
?>